package com.test.action;

import java.util.List;

import com.test.entity.CardType;
import com.test.entity.Cart;
import com.test.entity.CartItem;
import com.test.entity.Orders;
import com.test.entity.UserInfo;
import com.test.service.ShopCartService;
import com.test.service.UserInfoService;

public class UserAction extends BaseAction {
	private UserInfoService userInfoService;
	private int count;
	private String name;
	private ShopCartService shopCartService;
	private String method;
	private String cid;

	public String user1() throws Exception {
		// UserInfo userInfo=userInfoService.querymoney(name);

		UserInfo user = (UserInfo) this.getSession().get("userInfo");
		this.getRequest().put("money", user.getMoney());
		this.getRequest().put("jifen", user.getSumScore());
		List<Orders> list = userInfoService.OrderCount(user.getId());
		this.getRequest().put("count", list.get(0));
		return "user1";
	}

	public String delete() throws Exception {
		UserInfo userInfo = (UserInfo) this.getSession().get("userInfo");
		int cid1 = Integer.parseInt(cid);
		List<CardType> list = shopCartService.queryCarid(cid1);
		Cart cart = (Cart) this.getSession().get("cart");
		if (method.equals("remove")) {
			cart.delProduct(cid1);
		}
		if (method.equals("change")) {
			cart.getChange(cid1, count);
		}
		int count1 = cart.getCount();
		this.getSession().put("count", count1);
		List<CartItem> listcart = cart.getCards();
		this.getSession().put("cart", cart);
		this.getSession().put("listcart", listcart);
		double talprice = cart.getTotalMoney();
		this.getSession().put("talprice", talprice);
		return "user2";
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public UserInfoService getUserInfoService() {
		return userInfoService;
	}

	public void setUserInfoService(UserInfoService userInfoService) {
		this.userInfoService = userInfoService;
	}

	public ShopCartService getShopCartService() {
		return shopCartService;
	}

	public void setShopCartService(ShopCartService shopCartService) {
		this.shopCartService = shopCartService;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public String getCid() {
		return cid;
	}

	public void setCid(String cid) {
		this.cid = cid;
	}

}
